package com.android.superobstacleavoider;

import java.util.Random;

public class Obstacle {
	private Vector3 m_position;
	private float m_speed;
	private static Random m_rnd = new Random();
	private BoundingSphere m_bSphere;
	private boolean m_isAlive;

	public boolean isAlive() {
		if (getPosition().Z >= 15.0f) {
			m_isAlive = false;
		} else {
			m_isAlive = true;
		}
		return m_isAlive;
	}

	public void setIsAlive(boolean a_isAlive) {
		m_isAlive = a_isAlive;
	}

	public BoundingSphere getSphere() {
		return m_bSphere;
	}

	public Vector3 getPosition() {
		return m_position;
	}

	public void setPosition(Vector3 a_pos) {
		m_position = a_pos;
	}

	public float getSpeed() {
		return m_speed;
	}

	public void setSpeed(float a_speed) {
		m_speed = a_speed;
	}

	public Obstacle(int a_i) {
		m_position = new Vector3((float) (m_rnd.nextInt(40) - 20), -5.0f, 15.0f);
		m_bSphere = new BoundingSphere(m_position, 2.0f);
	}

	public void spawn() {
		m_position = new Vector3((float) (m_rnd.nextInt(40) - 20), -5.0f,
				-100.0f);
		
		switch (Game.getDifficulty()) {
		case 0:
			m_speed = 50.0f;
			break;
		case 1:
			m_speed = 80.0f;
			break;
		case 2:
			m_speed = 130.0f;
			break;
		}
		m_bSphere = new BoundingSphere(m_position, 2.0f);
	}

	public void update(float a_dt) {
		m_position.Z += m_speed * a_dt;
		m_bSphere.setCenter(m_position);
	}
}
